$(function() {
    var start       = moment().subtract(29, 'days');
    var end         = moment();
    var jdtime      = $('#jdtime');
    var fpddtime    = $('#fpddtime');
    var zztime      = $('#zztime');
    var yytime      = $('#yytime');
    var ddtime      = $('#ddtime');
    var mdfptime    = $('#mdfptime');
    var yyfptime    = $('#yyfptime');
    var lstime      = $('#lstime');
    var wddtime     = $('#wddtime');
    var yywdlstime  = $('#yywdlstime');
    var cjtime      = $('#cjtime');
    var wxtime      = $('#wxtime');
    var cztime      = $('#cztime');
    var lxsjtime    = $('#lxsjtime');
    var fktime    = $('#fktime');
    chushi(jdtime);
    chushi(fpddtime);
    chushi(zztime);
    chushi(yytime);
    chushi(ddtime);
    chushi(mdfptime);
    chushi(yyfptime);
    chushi(lstime);
    chushi(wddtime);
    chushi(yywdlstime);
    chushi(cjtime);
    chushi(cztime);
    chushi(lxsjtime);
    chushi(wxtime);
    chushi(fktime);
    function chushi(name) {
        if (name.val() == ''){
            datetime(name);
            name.val("");
        }else{
            name.on('focus',function () {
                var str = name.val();
                if(str!=''){
                    var string = str.split('~')
                    start = string[0];
                    end = string[1];
                }
                datetime(name);
            });

        }
        name.on('cancel.daterangepicker',function(ev, picker) {
            name.val('');
        });
    }
    function datetime(name) {
        name.daterangepicker({
            language: 'zh-CN',                                      //这里需要修改
            startDate: start,
            endDate: end,
            // singleDatePicker:true,
            ranges: {
                '今天': [moment(), moment()],
                '昨天': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                '本周': [moment().startOf('week').add(1,'days'),moment().endOf('week').add(1,'days')],
                '这个月': [moment().startOf('month'), moment().endOf('month')],
                '上个月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
                // '清除':  [qingchu(name)],
            },
            locale: {
                direction:"ltr",
                format: "YYYY-MM-DD",
                separator: "~",
                applyLabel: '确定',
                cancelLabel: '清除',
                fromLabel: '起始时间',
                toLabel: '结束时间',
                customRangeLabel: '自定义',
                daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
                monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
                    '七月', '八月', '九月', '十月', '十一月', '十二月'],
                firstDay: moment.localeData()._week.dow
            }
        });
    }
});
